package com.tepth.maintenancesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tepth.maintenancesystem.R;

import java.util.Vector;

/**
 * Created by LHQ on 2017/1/24.
 */

public class NFCMACAdapter extends BaseAdapter {
    private Vector<String> nfcList;
    private Context context;

    public NFCMACAdapter(Context context, Vector<String> nfcList) {
        this.nfcList = nfcList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return nfcList.size();
    }

    @Override
    public Object getItem(int position) {
        return nfcList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.nfc_mac_item, null);
            viewHolder.tv_nfc_mac = (TextView) convertView.findViewById(R.id.tv_nfc_mac);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv_nfc_mac.setText(nfcList.get(position));
        return convertView;
    }

    private static class ViewHolder {
        TextView tv_nfc_mac;
    }

    public void setNfcList(Vector<String> nfcList) {
        try {
            this.nfcList = nfcList;
            this.notifyDataSetChanged();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
